Am having a brain storm and anurism at the same time. I wonder about finding out of a Module handle is still valid; which it would not be if the module was closed after getting the hanle. Using the handle to find the module name usually produces exception violations. Is the following reliable?
Is is possible they could use that same Module handle address when they open some other module? -Louie llandale - Wed Dec 17 12:20:10 EST 2014 |
Re: Corrupt module handle If I would need to make a bet, I would say no ... (edit: stupid test program removed) Regards, Mathias |
Re: Corrupt module handle Hi Louie, sorry for my last answer it was not very verbose... I would think that your function will not work, simply because it presumes that a module will always get the same module handle (at the same memory location as before). To test this I would take the current Module, store the handle, then close it. Then open up all kinds of other modules. Close those. Then open the old module again and see if the handle is still the same. E.g.
Module mod = current
if (null mod) error "Start this script from an open module!"
print "Starting script from module " (fullName mod) "\n"
ModName_ mn = module mod
Folder fParent = getParentFolder mn
close mod
Item I; for I in fParent do {
if (type I != "Formal") continue
Module mTemp = read(fullName I, true);
}
Module modNew = read(fullName mn, true)
print "Same handle:" (modNew == mod) "\n"
Launching this on a module, with a couple of other modules in the same folder will give me: Launching script from module: /000__LinkPerformance_target/000__LinkPerformance/tgt_4 Oh no: Item /000__LinkPerformance_target/000__LinkPerformance/src got our old handle! Same handle:false which means, that DOORS reused the module handle for a different module. So in conclusion I would say that you never should reuse a module handle from a module that you have closed. If you want to have more safety for handles, then I would suggest you do not save module handles at all. Instead save string identifiers (URLS, unique IDs, etc.) that allow you to find an object / module. Then when you need a module handle, check if the module is already opened and get its handle or open the module to get a new one. This way you always have a good handle and do not need to worry about broken handles. I used this technique in BranchManager and it really saves a lot of headache. Regards, Mathias |
Re: Corrupt module handle Mathias Mamsch - Thu Dec 18 15:48:55 EST 2014 Hi Louie, sorry for my last answer it was not very verbose... I would think that your function will not work, simply because it presumes that a module will always get the same module handle (at the same memory location as before). To test this I would take the current Module, store the handle, then close it. Then open up all kinds of other modules. Close those. Then open the old module again and see if the handle is still the same. E.g.
Module mod = current
if (null mod) error "Start this script from an open module!"
print "Starting script from module " (fullName mod) "\n"
ModName_ mn = module mod
Folder fParent = getParentFolder mn
close mod
Item I; for I in fParent do {
if (type I != "Formal") continue
Module mTemp = read(fullName I, true);
}
Module modNew = read(fullName mn, true)
print "Same handle:" (modNew == mod) "\n"
Launching this on a module, with a couple of other modules in the same folder will give me: Launching script from module: /000__LinkPerformance_target/000__LinkPerformance/tgt_4 Oh no: Item /000__LinkPerformance_target/000__LinkPerformance/src got our old handle! Same handle:false which means, that DOORS reused the module handle for a different module. So in conclusion I would say that you never should reuse a module handle from a module that you have closed. If you want to have more safety for handles, then I would suggest you do not save module handles at all. Instead save string identifiers (URLS, unique IDs, etc.) that allow you to find an object / module. Then when you need a module handle, check if the module is already opened and get its handle or open the module to get a new one. This way you always have a good handle and do not need to worry about broken handles. I used this technique in BranchManager and it really saves a lot of headache. Regards, Mathias Yup. I came up with a strange way to figure out if a module was re-opened. I would insert a known dynamic module-close trigger in the open module. Later, if the module was open, I could see if it is "still" open by seeing if the trigger was still there. The idea is that I would not have to destroy and rebuild my other handles, such as all the Object handles stored in a Skip list. -Louie |